package com.wms.controller;

import com.wms.dto.ConfirmCorrectCountDto;
import com.wms.dto.ConfirmLossCountDto;
import com.wms.dto.StocktakingInfoDto;
import com.wms.pojo.PageResult;
import com.wms.pojo.Result;
import com.wms.service.StocktakingInfoService;
import com.wms.vo.StocktakingInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stocktaking")
public class StocktakingInfoController {
    
    @Autowired
    private StocktakingInfoService stocktakingInfoService;

    @GetMapping
    public Result page(Integer page, Integer pageSize, Integer id) {
        PageResult pageResult = stocktakingInfoService.queryPage(page, pageSize, id);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result saveStocktaking(@RequestBody StocktakingInfoDto dto){
        stocktakingInfoService.saveStocktaking(dto);
        return Result.success();
    }

    //回显数据
    @GetMapping("/{id}")
    public Result queryStocktakingById(@PathVariable Integer id){
        StocktakingInfoDto dto = stocktakingInfoService.queryStocktakingById(id);
        return Result.success(dto);
    }


    //删除
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        stocktakingInfoService.removeById(id);
        return Result.success();
    }

    //确定盘点
    @PutMapping
    public Result updateById(@RequestBody ConfirmCorrectCountDto dto){
        stocktakingInfoService.updateCorrectCountById(dto);
        return Result.success();
    }

    //确定报损
    @PutMapping("/loss")
    public Result updateLossCount(@RequestBody ConfirmLossCountDto dto){
        stocktakingInfoService.updateLossCount(dto);
        return Result.success();
    }
}
